package online.indigo6a.gohttp;

import online.indigo6a.gohttp.core.Http;
import online.indigo6a.gohttp.parser.GoHttpLexer;
import online.indigo6a.gohttp.parser.GoHttpParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

public class TestGoHttp {

    public static void main(String[] args) throws IOException {
        ANTLRInputStream input = new ANTLRInputStream(new FileInputStream("/Users/ljh/Documents/https2/httpbin.http"));
        GoHttpLexer lexer = new GoHttpLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        GoHttpParser parser = new GoHttpParser(tokens);
        ParseTree tree = parser.https();
//
        MyHttpListener listener = new MyHttpListener();
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(listener,tree);

        List<Http> https = listener.getHttps();
        System.out.println(https);
        System.out.println("pring result:"+https.size());
        System.out.println(https.get(0).toString());
        for(Http http:https) {
            System.out.println(http.getUrl());
            System.out.println(http.getHeaders());
            System.out.println("body:"+http.getBody());
        }

//        listener
//        GHttpVisitor visitor = new GHttpVisitor();
//        visitor.visit(tree);
//        System.out.println(tree.toStringTree(parser));

    }
}
